package com.service.impl;

import com.dao.ShopCartProductDao;
import com.dao.impl.ShopCartProductDaoImpl;
import com.pojo.ShopCartProduct;
import com.service.ShopCartProductService;

import java.util.List;

public class ShopCartProductServiceImpl implements ShopCartProductService {
    private ShopCartProductDao dao = new ShopCartProductDaoImpl();

    @Override
    public List<ShopCartProduct> findByShopCartID(String sCID) {
        return dao.selectByShopCartID(sCID);
    }

    @Override
    public boolean addSCP(ShopCartProduct shopCartProduct) {
        ShopCartProduct shopCartProduct1 = dao.selectByShopCartIDAndProductID(shopCartProduct.getShopCartId(), shopCartProduct.getProductId());
        if (shopCartProduct1==null)
            return dao.addSP(shopCartProduct)>0;
        else{
            shopCartProduct.setId(shopCartProduct1.getId());
            return dao.updateSC(shopCartProduct)>0;
        }


    }

    @Override
    public boolean deleteSCP(String id) {
        return dao.deleteSC(id)>0;
    }

    @Override
    public boolean deleteByCartIDAndPID(String cartID, String pid) {
        return dao.deleteSC(dao.selectByShopCartIDAndProductID(cartID,pid).getId())>0;
    }
}
